const MusicHttp = require("../../utils/MusicHttp")
Page({

  /**
   * 页面的初始数据
   */
  data: {

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: async function (options) {
    var {
      url
    } = options;
    var Hot = "3000/top/playlist/highquallity";
    var New = "3000/album/newest";
    var Dj = "3000/personalized/djprogram"
    var arr = [Hot, New, Dj];
    if(url==arr[0]){
      var music = await MusicHttp.getHttp(url);
      console.log(music);
      var dif = []
      music.data.playlists.forEach(item=>{
        var {name,id,coverImgUrl} = item;
        dif.push({
          name,
          id,
          coverImgUrl, 
        })
      })
      console.log(dif);
      this.setData({
        dif
      })
    }else if(url==arr[1]){
      var music = await MusicHttp.getHttp(url);
      console.log(music);
      var dif = []
      music.data.albums.forEach(item=>{
        var {name,id,blurPicUrl} = item;
        dif.push({
          name,
          id,
          coverImgUrl:blurPicUrl, 
        })
      })
      console.log(dif);
      this.setData({
        dif
      })
    }else if(url==arr[2]){
      var music = await MusicHttp.getHttp(url);
      console.log(music);
      var dif = []
      music.data.result.forEach(item=>{
        var {name,id,picUrl} = item;
        dif.push({
          name,
          id,
          coverImgUrl:picUrl,
        })
      })
      console.log(dif);
      this.setData({
        dif
      })
    }
  },
 OnClick(e){
   var {aid} = e.currentTarget.dataset;
   console.log(aid);
 wx.navigateTo({
   url: `../MoreDetail/MoreDetail?id=${aid}`,
 })
 },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})